﻿<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>要素多圈缓冲分析</title>
    <!--当前页面的样式-->
    <link href="../../css/leaflet/style.css" rel="stylesheet" type="text/css"/>
    <script include="json" src="./static/libs/include-leaflet-local.js"></script>

    <script type="text/javascript">
        //整个js文件都是严格模式下执行的
        "use strict";

        //定义全局变量
        var map, layer, resultLayer;
        //缓存结果图层的基地址
        var resultBaseUrl = "gdbp://MapGisLocal/OpenLayerVecterMap/sfcls/";
        var { protocol, ip, port } = window.webclient;

        /** 地图初始化函数*/
        function init() {
            //地图容器
            map = L.map('leaf_map', {
                //参考坐标系，默认是墨卡托坐标系（EPSG3857），EPSG4326为经纬度坐标系
                crs: L.CRS.EPSG4326,
                //显示中心
                center: [-10, 110],
                //最小显示等级
                minZoom: 0,
                //最大显示等级
                maxZoom: 10,
                //当前显示等级
                zoom: 1,
                //设置图像范围,
                maxBounds: L.latLngBounds(L.latLng(-180, -180), L.latLng(180, 180))
            });
            //矢量图层
            layer = new Zondy.Map.MapVectorLayer("gdbp://MapGisLocal/OpenLayerVecterMap/ds/世界地图经纬度/sfcls/世界政区", {
                //IGServer所在ip地址
                ip: `${ip}`,
                //IGServer请求端口号
                port: `${port}`,
                //设置图层能否重复显示。true代表显示唯一，false代表显示重复。
                noWrap: true,
                //缓存名称
                guid: (new Date()).getTime().toString()
            }).addTo(map);
        }

        /** 执行多圈缓冲区分析*/
        function multiBuffAnalysis() {
            clearA();
            //显示进度条
            startPressBar();
            //初始化Zondy.Object.FeatureGeometry对象
            var regGeo = new Zondy.Object.FeatureGeometry();
            //设置区要素的空间几何信息
            var gReg = new Zondy.Object.GRegion([
                new Zondy.Object.AnyLine([new Zondy.Object.Arc([
                    new Zondy.Object.Point2D(0.46, 30.1),
                    new Zondy.Object.Point2D(11.48, 6.22),
                    new Zondy.Object.Point2D(36.73, 7.6),
                    new Zondy.Object.Point2D(58.77, 25.51),
                    new Zondy.Object.Point2D(41.33, 49.39)
                ])])
            ]);
            //设置区要素几何信息的方法。
            regGeo.setRegGeom([gReg]);
            //实例化CAttStruct类
            var regAttStr = new Zondy.Object.CAttStruct({
                FldName: ["ID", "面积", "周长", "LayerID"],
                FldNumber: 4,
                FldType: ["FldLong", "FldDouble", "FldDouble", "FldLong"]
            });
            var values = [1, 0.00058032464704422, 0.132101984752282, 8];
            //创建属性信息对象
            var valuesRow = new Zondy.Object.CAttDataRow(values, 3286);
            //实例化FeatureBuffByMultiplyRing类，设置要素缓冲分析必要参数，输出分析结果到缓冲分析结果图层
            var featureBufByMR = new Zondy.Service.FeatureBuffByMultiplyRing({
                ip: `${ip}`,
                port: `${port}`,
                //设置多圈缓冲分析的缓冲半径字符串
                radiusStr: "5,10,20"
            });
            featureBufByMR.sfGeometryXML = JSON.stringify([regGeo]);
            featureBufByMR.attStrctXML = JSON.stringify(regAttStr);
            featureBufByMR.attRowsXML = JSON.stringify([valuesRow]);
            featureBufByMR.traceRadius = 0.0001;
            var resultname = "multiBuffAnalysisResultLayer" + getCurentTime();
            featureBufByMR.resultName = resultBaseUrl + resultname;
            //调用Zondy.Service.AnalysisBase基类的execute方法执行要素缓冲分析，AnalysisSuccess为回调函数。
            featureBufByMR.execute(AnalysisSuccess, "post", false, "json", AnalysisError);
        }

        /** 分析失败回调*/
        function AnalysisError(e) {
            //停止进度条
            stopPressBar();
        }

        /**回调函数，处理显示结果信息
         *@param(json对象)data获取结果对象
         */
        function AnalysisSuccess(data) {
            //停止进度条
            stopPressBar();
            if (!data.succeed) {
                alert("要素多圈缓冲分析失败，请检查参数！");
            } else {
                if (data.results.length !== 0 && data.results !== null) {
                    var resultLayerUrl = data.results[0].Value;
                    //将结果图层添加到地图视图中显示
                    resultLayer = new Zondy.Map.MapVectorLayer(encodeURIComponent(resultLayerUrl), {
                        //IGServer所在ip地址
                        ip: `${ip}`,
                        //IGServer请求端口号
                        port: `${port}`,
                        //设置图层能否重复显示。true代表显示唯一，false代表显示重复。
                        noWrap: true,
                        //缓存名称
                        guid: (new Date()).getTime().toString()
                    }).addTo(map);
                }
            }
        }

        /** 清除客户端分析结果信息*/
        function clearA() {
            //停止进度条
            stopPressBar();
            //清除缓冲区的图层
            if (resultLayer !== undefined) {
                resultLayer.remove();
            }
        }

        /** 当前日期加时间(如:2009-06-12-120000)*/
        function getCurentTime() {
            var now = new Date();
            //获取当前年份
            var year = now.getFullYear();
            //获取当前月份
            var month = now.getMonth() + 1;
            //获取当前日期
            var day = now.getDate();
            //获取当前时刻
            var hh = now.getHours();
            //获取当前分钟
            var mm = now.getMinutes();
            //获取当前秒钟
            var ss = now.getSeconds();
            //将当前的日期拼串
            var clock = year + "-";
            if (month < 10)
                clock += "0";
            clock += month + "-";
            if (day < 10)
                clock += "0";
            clock += day + "-";
            if (hh < 10)
                clock += "0";
            clock += hh;
            if (mm < 10) clock += '0';
            clock += mm;
            if (ss < 10) clock += '0';
            clock += ss;
            return (clock);
        }

        /** 停止进度条*/
        function stopPressBar() {
            document.getElementById('preview').style.display = "none";
        }

        /** 开始进度条动画*/
        function startPressBar() {
            document.getElementById('preview').style.display = "";
        }
    </script>
</head>

<body onload="init()">
<div id="preview" style="display: none; text-align: center; padding-top: 250px; font-weight: bold">
    <img src="./static/assets/graphic-image/39-1.gif" alt=''/>
    <br/>
    <br/>
    <span>正在缓冲区分析，请稍候</span>
</div>
<div class="ToolLib">
    <input type="button" class="ButtonLib" value="多圈缓冲区分析" onclick="multiBuffAnalysis()"/>
    <input type="button" class="ButtonLib" value="清除结果" onclick="clearA()"/>
</div>
<div id="leaf_map" style="width: 100%; height: 700px;">
</div>
</body>

</html>
